﻿using System;
using System.Collections.Generic;

namespace Citi.HeadCount.Domain
{
    public class ManagedSegment : EntityBase
    {
        public virtual string Code { get; set; }
        public virtual string Description { get; set; }
        public virtual Nullable<int> ParentId { get; set; }
        public virtual string ParentCode { get; set; }
        public virtual int TreeLevel { get; set; }
        public virtual DateTime UpdatedDate { get; set; }
        public virtual string Status { get; set; }

        public virtual ManagedSegment Parent { get; set; }

        public override bool IsSameInformation(EntityBase entity)
        {
            var managedSegment = (ManagedSegment)entity;

            return Code == managedSegment.Code
               && Description == managedSegment.Description
               && ((ParentId == managedSegment.ParentId || ParentId == Id) || (ParentCode == managedSegment.ParentCode || ParentCode == Code))
               && Status == managedSegment.Status;
            //return Id == managedSegment.Id
            //   && Code == managedSegment.Code
            //   && Description == managedSegment.Description
            //   && ParentId == managedSegment.ParentId
            //   && Status == managedSegment.Status;
        }
    }

    public class ManagedSegmentComparer : IEqualityComparer<ManagedSegment>
    {
        public bool Equals(ManagedSegment x, ManagedSegment y)
        {
            if (Object.ReferenceEquals(x, y)) return true;

            if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
                return false;

            return y.Id == x.Id
                && y.Code == x.Code
                && y.Description == x.Description
                && y.ParentId == x.ParentId
                && y.Status == x.Status;
        }

        public int GetHashCode(ManagedSegment item)
        {
            if (Object.ReferenceEquals(item, null)) return 0;

            int hashDescription = item.Description == null ? 0 : item.Description.GetHashCode();
            int hashId = item.Id == null ? 0 : item.Id.GetHashCode();
            int hashCode = item.Code == null ? 0 : item.Code.GetHashCode();
            int hashParentId = item.ParentId == null ? 0 : item.ParentId.GetHashCode();
            int hashStatus = item.Status == null ? 0 : item.Status.GetHashCode();

            return hashDescription ^ hashId ^ hashCode ^ hashParentId ^ hashStatus;
        }

    }
}


